package com.jay.cloudstudy.ui.settings

import android.graphics.BitmapFactory
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.jay.cloudstudy.R
import com.jay.cloudstudy.databinding.FragmentSettingsBinding
import com.jay.image.BitmapUtils
import com.jay.image.ImageLoader

class SettingsFragment : Fragment() {

    private lateinit var settingsViewModel: SettingsViewModel
    private var _binding: FragmentSettingsBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        settingsViewModel =
            ViewModelProvider(this).get(SettingsViewModel::class.java)

        _binding = FragmentSettingsBinding.inflate(inflater, container, false)
        val root: View = binding.root
        settingsViewModel.text.observe(viewLifecycleOwner, Observer {
        })

        ImageLoader.loadCircle(binding.imageIcon, R.mipmap.icon)

        binding.imageIconBg.setImageBitmap(
            BitmapUtils.blur(
                requireContext(),
                BitmapFactory.decodeResource(resources, R.mipmap.icon)
            )
        )

        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}